package com.shop.cereshop.commons.tencent.im.enums.im;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @description: 腾讯云IM 消息元素类别枚举
 * @author zdd
 * @date 2025/9/9 21:23
 * @version 1.0
 */
public enum MsgTypeEnum {

    TEXT("1", "文本消息"),

    LOCATION("2", "地理位置消息"),

    FACE("3", "表情消息"),

    CUSTOM("4", "自定义消息"),

    SOUND("5", "语音消息"),

    IMAGE("6", "图像消息"),

    FILE("7", "文件消息"),

    VIDEO_FILE("8", "视频消息"),

    ;


    private final String type;
    private final String name;

    // 预加载缓存
    private static final Map<String, MsgTypeEnum> TYPE_MAP =
            Arrays.stream(values()).collect(Collectors.toMap(MsgTypeEnum::getType, e -> e));

    private static final Map<String, MsgTypeEnum> NAME_MAP =
            Arrays.stream(values()).collect(Collectors.toMap(MsgTypeEnum::getName, e -> e));

    MsgTypeEnum(String type, String name) {
        this.type = type;
        this.name = name;
    }

    /**
     * 根据type返回枚举值
     *
     * @param type 类型字符串
     * @return 对应的枚举值，找不到则返回 null
     */
    public static MsgTypeEnum getByType(String type) {
        return StringUtils.isBlank(type) ? null : TYPE_MAP.get(type);
    }

    /**
     * 根据name返回枚举值
     *
     * @param name 名称字符串
     * @return 对应的枚举值，找不到则返回 null
     */
    public static MsgTypeEnum getByName(String name) {
        return StringUtils.isBlank(name) ? null : NAME_MAP.get(name);
    }

    public String getType() {
        return type;
    }

    public String getName() {
        return name;
    }

}
